package com.hypo.business.controller;

import com.hypo.business.domain.dto.AddGoodsDto;
import com.hypo.business.domain.dto.GoodsPageDto;
import com.hypo.business.domain.dto.ItemSpuDto;
import com.hypo.business.domain.dto.PageResultDto;
import com.hypo.business.service.ItemSpuService;
import com.hypo.response.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author admin
 */
@RestController
@RequestMapping("/goods")
@RequiredArgsConstructor
public class GoodsController {
    private final ItemSpuService itemSpuService;

    /**
     * 分页查询
     */
    @GetMapping("/list")
    public Result goodsPage(GoodsPageDto dto) {
        PageResultDto<ItemSpuDto> list = itemSpuService.goodsPage(dto);
        return Result.resp(list);
    }
    /**
     * 新增商品
     */
    @PostMapping("/add")
    public Result addGoods(@RequestBody AddGoodsDto dto) {
        itemSpuService.addGoods(dto);
        return Result.ok();
    }
    /**
     * 修改商品
     */
    @PutMapping("/update")
    public Result updateGoods(@RequestBody AddGoodsDto dto) {
        itemSpuService.updateGoods(dto);
        return Result.ok();
    }

    /**
     * 查询所有品牌
     */
    @GetMapping("/brands")
    public Result brands() {
        return Result.resp(itemSpuService.brands());
    }
    /**
     * 查询所有渠道商
     */
    @GetMapping("/suppliers")
    public Result suppliers() {
        return Result.resp(itemSpuService.suppliers());
    }
}
